package cn.blogger.service;

import cn.blogger.dao.UserDao;
import cn.blogger.entity.PageResult;
import cn.blogger.pojo.TUser;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * by:lin 2021/11/22 10:13
 */
@Service(interfaceClass = UserService.class)
@Transactional
public class UserServiceImpl implements UserService{
    @Autowired
    private UserDao userDao;
    //增加用户
    @Override
    public Object addUser(TUser user) {
        userDao.addUser(user);
        return null;
    }
    //查询全部用户
    @Override
    public PageResult selectAllUser(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<TUser> page = userDao.selectAllUser();
        return new PageResult(page.getTotal(),page.getResult());
    }
    //根据用户id删除用户
    @Override
    public Object removeUser(int uid) {
        userDao.removeUser(uid);
        return null;
    }
    //修改用户
    @Override
    public Object updateUser(TUser user) {
        userDao.updateUser(user);
        return null;
    }

    @Override
    public Object selectUserById(int uid) {
        return userDao.selectById(uid);
    }

}
